<?php
echo $this->navegacion($this->nav);

$domConfig = Zend_Registry::get('domConfig');
$perfil = App_Perfil::getInstance();
$perfil->cargar("ADMIN_AUTO1");


if ($perfil->crear()):

$autoOpen="false"; //esto se utiliza al final de la pagina para determinar si se abre o no el dialog al iniciar
?>
<BR>
<div align="right" class="buttons">
  <a class="btn btn-primary link-asignar" href="<?php echo $this->baseUrl("/autoevaluacion/detallecronograma/seleccionarprogramas");?>">
  <span class="glyphicon glyphicon-plus-sign"></span> Seleccionar Programas</a>
</div>

<div id="dialog-form" title="Asignar programas" style="display:none;">
  <span id="form-container"></span>
</div>
<?php
endif;

if(count($this->datos)>0):?>
<div id="DivContenedor">
<form action="<?=$this->baseUrl("/autoevaluacion/detallecronograma/guardardesasignarprogramas");?>" method="post">
<table id="table_id" align="center" class="display">
  <thead>
    <tr>
      <th width="5%">Codigo SNIES</th>
      <th width="15%">Sede - CUNAD</th>
      <th width="20%">Programa / Ubicaci&oacute;n</th>
      <th width="8%">Vencimiento</th>
      <th width="14%">Fecha inicio</th>
      <th width="14%">Fecha fin</th>
      <th width="20%">Observaci&oacute;n</th>
      <th width="5%"><input type="checkbox" value="chk_" id="chk_Todos" name="chk_Todos"></th>
    </tr>
  </thead>
  <tbody>
	<?php
	    foreach ($this->datos as $key => $value):
	?>
    <tr>
      <td><?php echo $value["codsnies"];?></td>
      <td><?php echo "{$value["nombresede"]}" ;?></td>
      <td><?php echo "{$value["nombreprograma"]}<BR>{$value["ubicacion"]}" ;?></td>
      <td align=center><?php echo "{$value["fechavencimientorc"]}" ;?></td>
      <td align=center><input type="text" readonly name="fechai_<?=$value["coddetallecronograma"]?>" id="fechai_<?=$value["coddetallecronograma"]?>" size="10" value="<?=$value["fechainicio"]?>""/></td>
      <td align=center><input type="text" readonly name="fechaf_<?=$value["coddetallecronograma"]?>" id="fechaf_<?=$value["coddetallecronograma"]?>" size="10" value="<?=$value["fechafin"]?>""/></td>

        <script type="text/javascript">
        	$( "#fechai_<?=$value["coddetallecronograma"]?>" ).datepicker({
        		showOn: "button",
        		buttonImage: "<?= $this->baseUrl("img/calendar.png")?>",
        		buttonImageOnly: true,
        		changeMonth: true,
        		changeYear: true,
    		      onClose: function( selectedDate ) {
    	  		        $( "#fechaf_<?=$value["coddetallecronograma"]?>" ).datepicker( "option", "minDate", selectedDate );
    	  		      }
        	});
        	$( "#fechaf_<?=$value["coddetallecronograma"]?>" ).datepicker({
        		showOn: "button",
        		buttonImage: "<?= $this->baseUrl("img/calendar.png")?>",
        		buttonImageOnly: true,
        		changeMonth: true,
        		changeYear: true
        	});
        
        </script>


      <td><textarea name="obs_<?=$value["coddetallecronograma"]?>" style="width:99%" rows="3" id="obs_<?=$value["coddetallecronograma"]?>"><?=$value["observaciondetalle"]?></textarea></td>
      <?php if ($perfil->eliminar()): ?>
	   	<td style="text-align:center;"><input type="checkbox" name="seleccionados[]" value="<?=$value["coddetallecronograma"];?>" /></td>
	  <?php endif; ?>
    </tr>
  <?php  endforeach;?>
  </tbody>
</table>
<div align="right"><input type="submit" value="Guardar / Des-Asignar a programas" class="btn btn-primary btn-sm " /></div>
</form>
</div>

<script type="text/javascript">
 $(function() {
	$('#table_id').dataTable({
		"bJQueryUI": true,
		"bAutoWidth": false,
 		"sPaginationType": "full_numbers",
 		"bStateSave": true,
 		"aoColumns": [
 	 		 			{ "sType": "numeric" },
 	 		 			null,
 	 		 			null,
 	 		 			null,
 	 		 			null,
 	 		 			null,
 	 		 			null,
 	 		 			{ "bSortable": false, "bSearchable": false }
 	 		 		 ]
 	 		  		
	});
});
</script>
<?php else:?>
<br/>
<?php echo $this->mensajes("No existen registros");?>
<?php endif;?>
<script type="text/javascript">
$(function() {
	$("#dialog-form").dialog({
		autoOpen: <?php echo $autoOpen;?>,
		height: 500,
		width: 800,
		modal: true,
		buttons: {
			'Cancelar': function() {
				$(this).dialog('close');
			}
		}
	});
	
	$('.link-asignar').click(function(e) {
		e.preventDefault();
		$("#form-container").load($(this).attr("href"), function(response, status, xhr) {
			$("#dialog-form").dialog("open");
		});
	});

});

$("#chk_Todos").change(function(){
	if($(this).is(":checked")) {
		$(this).closest('#DivContenedor').find('input[type=checkbox]').attr('checked', true);
	}else{
      	$(this).closest('#DivContenedor').find('input[type=checkbox]').attr('checked', false);
	}
});
</script>
